package shuiyuqing.fragments;

import android.app.Activity;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ListView;

import com.xkh.xkh.R;

import shuiyuqing.model.Type;
import shuiyuqing.network.beans.IrrBRStadia;
import shuiyuqing.views.adapters.WatchPointAdapter;

/**
 * 监测点查询
 * Created by 凯 on 2015/11/9.
 */
public class WatchPointFragment extends DialogFragment {

    Delegate delegate;

    ListView lv_watchPoint;

    WatchPointAdapter watchPointAdapter;

    public void setWatchPointAdapter(WatchPointAdapter watchPointAdapter) {
        this.watchPointAdapter = watchPointAdapter;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = inflater.inflate(R.layout.fragment_watchpoint,null);
        initview(view);
        return view;
    }

    // 初始化
    private void initview(View view) {
        lv_watchPoint = (ListView) view.findViewById(R.id.id_lv_sel_watchPoint);
        if (watchPointAdapter == null)
        {
            watchPointAdapter = new WatchPointAdapter();
            watchPointAdapter.setType(Type.WATER);
        }
        lv_watchPoint.setAdapter(watchPointAdapter);

        lv_watchPoint.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                IrrBRStadia stadia = (IrrBRStadia) view.getTag(R.id.id_point);
                dismiss();
                delegate.selPoint(stadia);
            }
        });
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        if (activity instanceof Delegate)
        {
            delegate = (Delegate) activity;
        }
    }

    public static interface Delegate
    {
        public void selPoint(IrrBRStadia stadia);
    }
}
